package com.kaifamiao.contraller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.kaifamiao.model.UserModel;
import com.kaifamiao.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping(value = "lll")
public class LoginUserController {

    @Autowired
    private UserService service;
//    private static List<UserModel> userList;
    @RequestMapping("/login")
    public ModelAndView login(@RequestParam("accountName") String accountName,
                        @RequestParam("password") String password,
                        HttpServletResponse resp,
                        HttpServletRequest req) {
        UserModel model = new UserModel();
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("msg",service.findByUser(model));

//        userList = service.findByUser(model);

        if (service.findByUser(model).size() > 0) {
            System.out.println("用户名或密码正确");
            modelAndView.setViewName("/WEB-INF/login.jsp");

        } else {
            System.out.println("用户名或密码不正确");
        }
        return modelAndView;

    }
}
